package com.thinkgem.jeesite.modules.euler.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.euler.entity.TaskStatEntity;
import com.thinkgem.jeesite.modules.euler.service.MonitorService;

/**
 * @describe:
 * @author leo E-mail: zhangle231@163.com
 * @version 下午3:57:45
 */
@Controller
@RequestMapping(value = "{adminPath}/monitor")
public class MonitorController extends BaseController {
	
	@Autowired
	MonitorService monitorService;
	
	@RequestMapping(value = { "index", "" })
	public String monitor() {
		return "modules/euler/eulerMonitor";
	}
	
	@RequestMapping(value = "addForm")
	public String addForm(TaskStatEntity taskStatEntity, Model model) {
		model.addAttribute("taskStatEntity", taskStatEntity);
		return "modules/euler/eulerMonitorAddForm";
	}
	
	@RequestMapping(value = "save")
	public String save(TaskStatEntity taskStatEntity, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, taskStatEntity)){
			return addForm(taskStatEntity, model);
		}
		
		monitorService.save(taskStatEntity);
		
		addMessage(redirectAttributes, "保存数据'" + taskStatEntity.getTaskName() + "'成功");
		
		return "redirect:" + adminPath + "/monitor/?repage";
	}
}
